package com.xiangying.utils;

import java.io.Serializable;

import com.xiangying.entity.common.Result;
import com.xiangying.entity.common.ResultEnum;

/**
 * 返回帮助类
 * @author luolihong
 *
 */
public class ResultUtils implements Serializable {

	private static final long serialVersionUID = 1267479780124412937L;

	/**
	 * 成功返回
	 * @param object
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Result success(Object object) {
		Result result = new Result();
		result.setCode(ResultEnum.SUCCESS.getCode());
		result.setMessage(ResultEnum.SUCCESS.getMsg());
		result.setData(object);
		return result;
	}

	/**
	 * 成功返回
	 * @return
	 */
	public static Result<String> success() {
		Result<String> result = new Result<String>();
		result.setCode(ResultEnum.SUCCESS.getCode());
		result.setMessage(ResultEnum.SUCCESS.getMsg());
		return result;
	}

	/**
	 * 错误返回
	 * @param code
	 * @param msg
	 * @return
	 */
	public static Result<String> error(Integer code, String msg) {
		Result<String> result = new Result<String>();
		result.setCode(code);
		result.setMessage(msg);
		return result;
	}
}
